package queue

import "gitee.com/hlwqds/go-algorithm/linkList"

type QueueLinkList struct {
	Size int
	head *linkList.LNode
	end *linkList.LNode
}

func (q *QueueLinkList) IsEmpty() bool {
	if q != nil && q.head != nil {
		return false
	}
	return true
}

func (q *QueueLinkList) GetFront() int {
	if q.IsEmpty() {
		panic("q is Empty")
	}
	return q.head.Data
}

func (q *QueueLinkList) GetBack() int {
	if q.IsEmpty() {
		panic("q is Empty")
	}
	return q.end.Data
}

func (q *QueueLinkList) Dequeue()(d int) {
	if q.IsEmpty(){
		panic("q is Empty")
	}
	d = q.head.Data
	q.head = q.head.Next
	if q.head == nil {
		q.end = nil
	}
	return d
}

func (q *QueueLinkList) Enqueue(d int) {
	node := &linkList.LNode{
		Data: d,
		Next: nil,
	}
	if q.end == nil {
		q.head = node
		q.end = node
	} else {
		q.end.Next = node
		q.end = node
	}
}
